﻿Imports System.Linq

Partial Class GridView2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not IsPostBack Then
            GridView2.PageIndex = 0
            BindGridView()
        End If
    End Sub

    Private Function GetTotalRecords() As Integer
        Return 300
    End Function

    Private Function GetSource(PageSize As Integer, PageIndex As Integer) As Object
        Dim list As New List(Of ListItem)


        For i As Integer = 0 To GetTotalRecords()
            list.Add(New ListItem(String.Format("Name {0}", i), i.ToString))
        Next

        Return list.Skip((PageIndex) * PageSize).Take(PageSize).ToList
    End Function

    Private Sub BindGridView()
        GridView2.PageSize = 15
        GridView2.DataSource = GetSource(15, GridView2.PageIndex)
        GridView2.VirtualItemCount = GetTotalRecords()
        GridView2.DataBind()
    End Sub

    Protected Sub GridView2_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView2.PageIndexChanging
        GridView2.PageIndex = e.NewPageIndex
        BindGridView()
    End Sub
End Class
